#include<bits/stdc++.h>
using namespace std;
int n;
struct node{
	string s;
	int num;
};
vector<node> server,client;
bool chk(string s)
{
	int p=0,m=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='.')
			p++;
		if(s[i]==':')
			m++;
	}
	if(p!=3||m!=1)
		return false;
	string a="",b="",c="",d="",e="";
	int point=0,a1,b1,c1,d1,e1;
	a1=b1=c1=d1=e1=0;
	for(;point<s.size();point++)
	{
		if(s[point]=='.')
			break;
		a=a+s[point];
		a1*=10;
		a1+=s[point]-48;
	}
	point++;
	if(a[0]=='0'&&a.size()>1)
		return false;
	if(a1<0||a1>255)
		return false;
	for(;point<s.size();point++)
	{
		if(s[point]=='.')
			break;
		b=b+s[point];
		b1*=10;
		b1+=s[point]-48;
	}
	point++;
	if(b[0]=='0'&&b.size()>1)
		return false;
	if(b1<0||b1>255)
		return false;
	for(;point<s.size();point++)
	{
		if(s[point]=='.')
			break;
		c=c+s[point];
		c1*=10;
		c1+=s[point]-48;
	}
	point++;
	if(c[0]=='0'&&c.size()>1)
		return false;
	if(c1<0||c1>255)
		return false;
	for(;point<s.size();point++)
	{
		if(s[point]==':')
			break;
		d=d+s[point];
		d1*=10;
		d1+=s[point]-48;
	}
	point++;	
	if(d[0]=='0'&&d.size()>1)
		return false;
	if(d1<0||d1>255)
		return false;

	for(;point<s.size();point++)
	{
		e=e+s[point];
		e1*=10;
		e1+=s[point]-48;
	}
	point++;
	if(e[0]=='0'&&e.size()>1)
		return false;
	if(e1<0||e1>65535)
		return false;
	return true;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	ios::sync_with_stdio(false);
	string op,ad;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>op;
		if(op=="Server")
		{
			cin>>ad;
			if(!chk(ad))
				cout<<"ERR"<<endl;
			else
			{
				bool f=false;
				for(int j=0;j<server.size();j++)
				{
					if(server[j].s==ad)
					{
						f=true;
						cout<<"FAIL"<<endl;
						break;
					}
				}
				if(!f)
				{
					server.push_back({ad,i});
					cout<<"OK"<<endl;
				}
					
			}
		}
		else
		{
			cin>>ad;
			if(!chk(ad))
				cout<<"ERR"<<endl;
			else
			{
				bool f=false;
				for(int j=0;j<server.size();j++)
				{
					if(server[j].s==ad)
					{
						f=true;
						cout<<server[j].num<<endl;
						break;
					}
				}
				if(!f)
					cout<<"FAIL"<<endl;
			}
		}
	}
	return 0;
} 
